# To change this template, choose Tools | Templates
# and open the template in the editor.

__author__="yangqibin"
__date__ ="$Nov 13, 2011 4:25:18 AM$"

import web
import res_code
import models.register

t_globals = { 'datestr':web.datestr }

render = web.template.render('templates', globals=t_globals)

class Register:

    form = web.form.Form(
      web.form.Textbox('username', web.form.notnull, description='Username:'),
      web.form.Password('password', web.form.notnull, description='Password'),
      web.form.Password('password_confirm', web.form.notnull, description='Password confirm:'),
      web.form.Textbox('email', web.form.notnull, description='E-mail:' ),
    )
    
    def GET(self):
        return render.register()

    def POST(self):
        username = web.inputs().username
        password = web.inputs().password
        password_confirm = web.inputs().password_confirm
        email = web.inputs().email

        if password != password_confirm:
            return render.register(res_code.get_extra_info(res_code.err_password_confirm_error))
        
        res = models.register(user_name, password, email)

        if res == res_code.success:
            raise web.seeother('/')
        else:
            return render.register(res_code.get_extra_info(res))

if __name__ == "__main__":
    print "Hello World"
